const axios = require('axios');

const axiosConfig = {
  baseURL: 'https://api.weixin.qq.com/cgi-bin',
  timeout: 5000
}

// 拦截器
// service.interceptors.request.use(config => config, err => Promise.reject());
axios.interceptors.response.use(resp => {
  if(resp.data.errcode || resp.data.errmsg) return Promise.reject(resp.data);
  return resp;
}, err => Promise.reject());

const aget = (url, params = {}, opt = {}) => axios.get(url, Object.assign({}, axiosConfig, { params }, opt))

const apost = (url, data = {}, params = {}, opt= {}) => axios.post(url, data, Object.assign({}, axiosConfig, { params }, opt))

module.exports = { aget, apost }